import { validateThreeLayerArchitecture, summarizeCoverage } from "../tools/validator";

interface CoverageOptions {
  component: string;
  fieldsFile: string;
  editFile: string;
  previewFile: string;
  reportPath?: string;
}

export async function computeFieldCoverage(options: CoverageOptions) {
  const report = await validateThreeLayerArchitecture(options.component, {
    fieldsFile: options.fieldsFile,
    editFile: options.editFile,
    previewFile: options.previewFile,
  });

  const summary = await summarizeCoverage(report, options.component);

  if (options.reportPath) {
    const { writeJsonFile } = await import("../tools/data-processor");
    await writeJsonFile(options.reportPath, { component: options.component, report, summary });
  }

  return { report, summary };
}
